namespace Core.Features
{
    using Base;
    using Contracts.Enums;
    using Resources;
    using System;

    
    public sealed class ArmorRepairAmount<T> : FeatureBase<object>
    {
        public ArmorRepairAmount(){}

        public ArmorRepairAmount(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Repair amount"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup { get { return FeatureGroupsEnum.Defence; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.ArmorRepairAmount; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_hp; } }


        public override void SetModifiedValue(Contracts.Interfaces.IAgent agent, Contracts.Interfaces.IRobot robot)
        {
            if (agent == null || robot == null) return;

            double extension = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType);
            double robotBonus = robot.Modifiers.SumModifiersValues(agent.Extensions, FeatureTypesEnum.Module, this.FeatureType);

            double temp = (double)Value * (1 + (extension + robotBonus));

            temp = robot.Modules.Aggregate(temp, (current, modifier) => current * (1 + Math.Abs(modifier.Value)), FeatureTypesEnum.Module, this.FeatureType, ModuleGroupsEnum.ArmorRepairersTunings);

            // nexus Bonus
            double nexusBonus = robot.Modules.SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType, ModuleGroupsEnum.NexusModuleRepairer);
            double nexusSkillBonus = agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType);

            double nexusTotalBonus = 0;

            if (nexusBonus != 0)

                nexusTotalBonus = Math.Abs(nexusBonus) + (((1 + Math.Abs(nexusBonus)) * Math.Abs(nexusSkillBonus)) / 100);

            temp = temp * (1 + nexusTotalBonus);

            ModifiedValue = IsRounded
                                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                                : Math.Round(temp, 2);

        }
    }
}